﻿
namespace SvGame.Cached;

public static partial class CacheGame
{
    //玩家缓存列表
    public static Dictionary<long, Player> DictPlayer = new();

    public static bool GetPlayer(long puid, out Player player)
        => DictPlayer.TryGetValue(puid, out player);

    // 广播消息
    public static void Broadcast<T>(T msg) where T : gpb::IMessage
    {
        foreach (var player in DictPlayer.Values)
        {
            if (player.Online) 
            {
                player.Send(msg);
            }
        }
    }
    // 广播消息 带条件
    public static void BroadcastWhere<T>(T msg, Func<Player, bool> selector) where T : gpb::IMessage
    {
        foreach (var player in DictPlayer.Values)
        {
            if (player.Online && selector(player))
            {
                player.Send(msg);
            }
        }
    }

}
